import QtQuick 2.0
import QtQuick.Controls 1.1
import org.qtproject.znews_qt 1.0
import "../delegate"
import "../articlecontent"
import "../common"

MainBasePage {

    id: id_mainwindow

    state:  _STATE_SHOWMAINVIEW
    states: [
        State {
            name: _STATE_SHOWLEFTMENU
            PropertyChanges { target: id_leftmenu; x: 0 }
            PropertyChanges { target: id_mainview; opacity: 0.3 }
        },

        State{
            name: _STATE_SHOWMAINVIEW
            PropertyChanges { target: id_leftmenu; x: - id_leftmenu.width - 10}
            PropertyChanges { target: id_mainview; opacity:1 }
        }
    ]
    transitions: Transition {
        NumberAnimation { properties: "x,opacity"; duration: 600; easing.type: Easing.OutQuint }
    }

    m_header.title: "Tin mới ..."

    m_header.onLeftMenuClicked: {
        console.log("Main show leftmenu ");
        if (id_mainwindow.state !== _STATE_SHOWLEFTMENU) {
            id_mainwindow.state = _STATE_SHOWLEFTMENU
            id_mainview.focus = false;
        } else {
            id_mainwindow.state = _STATE_SHOWMAINVIEW
        }

    }

    //---------------signal-------------------------------------------------------------------------------------

    //lay data theo nguon bao
    signal getArticleCategoryRequestFromSource(int sourceId);

    //---------------funtion-------------------------------------------------------------------------------------
    function onAddMenuCategoryInfo(idCategoryInfo, icon, name)
    {
        id_leftmenu.addMenuDelegate(idCategoryInfo, icon,name);
    }


    //---------------property-------------------------------------------------------------------------------------
    // property and const
    // const state
    property string _STATE_SHOWMAINVIEW : "state_showmainview"
    property string _STATE_SHOWLEFTMENU : "state_showleftmenu"


    Item {
        // mainview kieu item : de set thuoc tinh opacity
        id: id_mainview
        anchors.top: m_header.bottom;
        anchors.topMargin: 5;
        width: id_mainwindow.width

        ListModel {
            id: modelListCategory
        }

        ListView {
            id: listViewCategory
            //y: m_header.height + 5   /* chu y header */
            width: id_mainwindow.width
            height: id_mainwindow.height
            orientation: ListView.Horizontal

            model : ApplicationInfo.categoryListModel;

            delegate: CatergoryDelegate {
                m_id: idcategorydelegate
            }

            onMovementEnded: {
                if (listViewCategory.atXEnd) {
                    console.info("count listviewcategory ", listViewCategory.count );
                    ApplicationInfo.onUpdateMoreCategoryRequest(listViewCategory.count);
                }
            }

            snapMode: ListView.SnapOneItem;
        }
    }


    Menu {
        id: id_leftmenu
    }



    Stack.onStatusChanged: {

        m_isLocked = !(Stack.status === Stack.Active)
        console.info("Stack onStatusChanged " , m_isLocked)

    }

}

